﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UtilsCache;
using UtilsORM;
using UtilsORM.MySqlData;

namespace ServiceWeb.DBGateway
{
    public class DBIotDeviceVariableCache
    {
        public DBIotDeviceVariableCache()
        {

        }
        EFYihongIotContext ef = new EFYihongIotContext();

        /// <summary>
        /// 缓存增加 获取变量列表
        /// </summary>
        /// <param name="cguid"></param>
        /// <returns></returns>
        public List<iot_device_model_variable> getVariableListByCache()
        {
            List<iot_device_model_variable> list = UtilMemoryCacheHelper.StringGet<List<iot_device_model_variable>>("deviceVariableList");
            if (list == null)
            {
                list = ef.iot_device_model_variable.Where(c => c.v_status == 0).ToList();
                UtilMemoryCacheHelper.StringSet("deviceVariableList", list, 1);
            }
            return list;
        }
        /// <summary>
        /// 缓存增加 获取变量列表
        /// </summary>
        /// <param name="cguid"></param>
        /// <returns></returns>
        public iot_device_model_variable getVariableByKeyCache(string key)
        {
            EFYihongIotContext ef = new EFYihongIotContext();
            iot_device_model_variable list = UtilMemoryCacheHelper.StringGet<iot_device_model_variable>("getVariableByKey" + key);
            if (list == null)
            {
                list = ef.iot_device_model_variable.Where(c => c.v_key == key).FirstOrDefault();
                UtilMemoryCacheHelper.StringSet("getVariableByKey" + key, list, 1);
            }
            return list;
        }
    }
}
